﻿@model Atomic.Permission.Entities.FunPointEntity
<script type="text/javascript">
    var jqEditPanel;
    $(function () {
        jqEditPanel = $('#roleEditPanel');
        jqEditPanel.dialog({
            title: '新建/编辑项',
            buttons: [
                {
                    text: '保存',
                    handler: function () {
                        $('form', jqEditPanel).submit();
                    }
                }
            ]
        });

        $('#list').datagrid({
            url: '@Url.Content("~/Permission/OperatePointList")',
            fit: true,
            border: false,
            nowrap: false,
            singleSelect: true,
            toolbar: [
                    {
                        text: "新建",
                        iconCls: "icon-add",
                        handler: function () {
                            $('#ID', jqEditPanel).val(0);
                            $('#FunPointID', jqEditPanel).val(0);
                            $('input:text,textarea', jqEditPanel).val('');
                            $('#Enabled', jqEditPanel).attr('checked', true);
                            jqEditPanel.dialog('open');
                        }
                    },
                    {
                        text: "编辑",
                        iconCls: "icon-edit",
                        handler: function () {
                            var data = $('#list').datagrid('getSelected');
                            if (null == data) {
                                $.messager.alert('提示信息', '请选择要编辑的项', 'warning');
                            } else {
                                $('#ID', jqEditPanel).val(data.ID);
                                $('#FunPointID', jqEditPanel).val(data.FunPointID);
                                $('#Key', jqEditPanel).val(data.Key);
                                $('#Name', jqEditPanel).val(data.Name);
                                $('#Enabled', jqEditPanel).attr('checked', data.Enabled);
                                jqEditPanel.dialog('open');
                            }
                        }
                    },
                    {
                        text: "删除",
                        iconCls: "icon-remove",
                        handler: function () {
                            var data = $('#list').datagrid('getSelected');
                            if (null == data) {
                                $.messager.alert('提示信息', '请选择要删除的项', 'warning');
                            } else {
                                $.messager.confirm('提示信息', '删除该项可能导致对应功能不再可用。确定删除选中项？', function (btn) {
                                    if (btn) {
                                        $.post('@Url.Content("~/Permission/OperatePointRemove")',
                                        {
                                            id: data.ID
                                        },
                                        function () {
                                            $('#list').datagrid('reload');
                                        });
                                    }
                                });
                            }
                        }
                    }
                ],
            columns: [[
                    { field: 'Key', title: '键值', width: 250 },
                    { field: 'Name', title: '操作名称', width: 150 },
                    { field: 'FunPointName', title: '专属页面', width: 150 },
                    { field: 'Enabled', title: '是否启用', width: 60,
                        formatter: function (v) {
                            if (v) {
                                return '是';
                            } else {
                                return '<span style="color:#f00;">否<span>';
                            }
                        }
                    }
                ]]
        });
    });
    function onSuccess(data) {
        if (data.Success) {
            jqEditPanel.dialog('close');
            $('#list').datagrid('reload');
        }
    }
</script>
<div id="list">
</div>
<div id="roleEditPanel">
    @using (Ajax.BeginForm("OperatePointAddOrUpdate", new AjaxOptions
    {
        HttpMethod = "Post",
        OnSuccess = "onSuccess"
    }))
    {
        @Html.HiddenFor(m => m.ID)
        @Html.HiddenFor(m => m.FormID)
        <table class="form-tab top" style="width: 450px">
            <tr>
                <td class="left">
                    @Html.LabelFor(m => m.Key)：
                </td>
                <td>
                    @Html.TextBoxFor(m => m.Key, new { @class = "text" })
                    @Html.ValidationMessageFor(m => m.Key)
                </td>
            </tr>
            <tr>
                <td class="left">
                    @Html.LabelFor(m => m.Name)：
                </td>
                <td>
                    @Html.TextBoxFor(m => m.Name, new { @class = "text" })
                    @Html.ValidationMessageFor(m => m.Name)
                </td>
            </tr>
            <tr>
                <td class="left">
                    @Html.LabelFor(m => m.Enabled)：
                </td>
                <td>
                    @Html.CheckBoxFor(m => m.Enabled, new { @checked = true })
                </td>
            </tr>
        </table>
    }
</div>
